package com.sky.controller.admin;

import com.github.pagehelper.PageHelper;
import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.entity.Orders;
import com.sky.mapper.AdiminOrderMapper;
import com.sky.result.PageResult;
import com.sky.result.Result;

import com.sky.service.AdiminOrderService;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/order")
@Api(tags = "商家订单相关接口")
@Slf4j
public class AdminOrderController {

    @Autowired
    private AdiminOrderService adiminOrderService;


    @GetMapping("/conditionSearch")
    public Result<PageResult> OrderSearch( OrdersPageQueryDTO ordersPageQueryDTO) {

        log.info("商家搜索订单");

        PageResult orderVOList = adiminOrderService.OrderSearch(ordersPageQueryDTO);

        return Result.success(orderVOList);
    }

    @GetMapping("/details/{id}")
    public Result<OrderVO> getOrderDetailById(@PathVariable Long id) {
        log.info("通过id查询订单详情 {}",id);
         OrderVO orderVO = adiminOrderService.selectById(id);
         return Result.success(orderVO);
    }

    @GetMapping("/statistics")
    public Result<OrderStatisticsVO> getOrderStatistics() {
        log.info("查询各个状态的订单数量");
        OrderStatisticsVO orderStatisticsVO = adiminOrderService.getOrderStatistics();

        System.out.println("待派送数量:"+orderStatisticsVO.getConfirmed());
        System.out.println("待接单数量:"+orderStatisticsVO.getToBeConfirmed());
        System.out.println("派送中:"+orderStatisticsVO.getDeliveryInProgress());

        return Result.success(orderStatisticsVO);
    }
    @PutMapping("/confirm")
    public Result confirmOrder( @RequestBody OrdersConfirmDTO ordersConfirmDTO) {
        log.info("商家接单 {}",ordersConfirmDTO);
        adiminOrderService.confirmOrder(ordersConfirmDTO);

        return Result.success();
    }
    @PutMapping("/rejection")
    public Result rejectOrder(@RequestBody OrdersRejectionDTO ordersRejectionDTO) {
        log.info("商家拒单 {}",ordersRejectionDTO);
        adiminOrderService.rejectOrder(ordersRejectionDTO);

        return Result.success();
    }
    @PutMapping("/delivery/{id}")
    public Result sendOrder(@PathVariable Long id) {
        log.info("商家派送订单 {}",id);
        adiminOrderService.sendOrder(id);

        return Result.success();
    }
    @PutMapping("/complete/{id}")
    public Result completeOrder(@PathVariable Long id) {
        log.info("商家完成订单 {}",id);
        adiminOrderService.compelete(id);

        return Result.success();
    }
    @PutMapping("/cancel")
    public Result cancelOrder(@RequestBody OrdersCancelDTO ordersCancelDTO) {
        log.info("商家取消订单 {}",ordersCancelDTO);
        adiminOrderService.cancelOrder(ordersCancelDTO);

        return Result.success();
    }
}
